# -*- encoding=utf8 -*-
__author__ = "yangxianming"

from airtest.core.api import *
# ST.PROJECT_ROOT = "E:\AirtestWorkSpace\fuyuanwaiUItest"
# using(r"E:\AirtestWorkSpace\fuyuanwaiUItest\common.air")
# from common import *

auto_setup(__file__)

#拿到设备编号
import sys
args = sys.argv
devicePid = args[4].split("/")[3]
print("--------" + devicePid)
rootArr = args[2].split("\\")
scriptRoot = ""
for i in range(len(rootArr) - 1):
    scriptRoot = scriptRoot + rootArr[i] + "\\"
print("--------" + scriptRoot)

#对更目录下设变编号文件做注册登记操作 1代表在使用  0代表停止使用
with open(scriptRoot + devicePid, 'w') as f:
    f.write('1')
    
using(scriptRoot + "common.air")

from common import *
stop_app("com.alibaba.android.rimet")
start_app("com.alibaba.android.rimet")

try:

    sleep(1.0)
    openKoufu()
    sleep(1.0)
    openScene("yiliaofuwu")
    
    ##医疗服务
    sleep(15.0)
    
    #点个人服务套餐
    touch(Template(r"tpl1681193322530.png", record_pos=(0.257, 0.24), resolution=(1080, 1920)))
    sleep(1.0)
    #点坐标的第一个商品
    touch((450,1520))
    sleep(1.0)
    touch(Template(r"tpl1681195309234.png", record_pos=(0.298, 0.821), resolution=(1080, 1920)))
    sleep(1.0)
    touch(Template(r"tpl1681195329237.png", target_pos=6, record_pos=(-0.016, 0.686), resolution=(1080, 1920)))
    sleep(1.0)
    touch(Template(r"tpl1681195447023.png", record_pos=(0.298, 0.824), resolution=(1080, 1920)))
    sleep(9.0)
    touch(Template(r"tpl1681195488279.png", record_pos=(-0.002, 0.8), resolution=(1080, 1920)))
    sleep(2.0)
    #验证是否跳转我们的收银台
    assert_exists(Template(r"tpl1681195514073.png", record_pos=(-0.281, 0.481), resolution=(1080, 1920)), "验证是否跳转我们的收银台")
    sleep(5.0)
    
except Exception as e:
    print(e)
finally:
    sleep(1.0)
    stop_app("com.alibaba.android.rimet")
    #完成测试等级设备为0以便被其他脚本使用
    with open(scriptRoot + devicePid, 'w') as f:
        f.write('0')